<?php
class settingController extends adminController{

	public function index(){
		$this->themes_list=model('setting')->themes_list();
		$this->tpl_list=model('setting')->tpl_list();
		$this->show();
	}

	//保存配置文件
	public function save_config(){
		$data = $_POST; //接收表单数据

		$config=require(BASE_PATH.'/config.php');

		function conReplace($value){
			if($value=='true') return true;
			if($value=='false') return false;
			if(preg_match("/^\d*$/",$value) && strlen($value)<10) return intval($value);
			return $value;  
		}

		foreach ($data as $key => $value) {
			if(is_array($value)){
				foreach ($value as $k=> $v) {
					$config[$key][$k]=conReplace($v);
				}
			}else $config[$key] = conReplace($value);
		}

		if (model('setting')->save_config(BASE_PATH . '/config.php',$config)) {
			$this->msg('网站配置成功！');
		}else{
			$this->msg('网站配置失败，请检查是否有权限写入！',0);
		}

	}

}